package com.cqc.customtoast01;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by ${cqc} on 2017/6/6.
 */

public class CustomToast {

    private static Toast toast;

    public static void showToast(Context context, String content) {

        if (toast == null) {
            View toastView = LayoutInflater.from(context).inflate(R.layout.custom_toast, null);
//          ImageView iv = (ImageView) toastView.findViewById(R.id.iv);
            TextView tv = (TextView) toastView.findViewById(R.id.tv);
            tv.setText(content);

            toast = new Toast(context);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.setView(toastView);
            toast.setGravity(Gravity.CENTER, 0, 0);
        }
        toast.show();
    }
}
